package com.ssm.service.impl;

import com.ssm.mapper.UserMapper;
import com.ssm.pojo.TbUser;
import com.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author 咕唧
 * @Date 2022/5/22 20:47
 * @Version 1.0
 */
@Service
@Transactional  //声明当前类中的操作进行事务管理
public class UserServiceImpl implements UserService {
    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public TbUser findById(Long id) {
        return userMapper.findById(id);
    }

    @Override
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)//优先级高于类上的
    public void addUser(TbUser user) {
        userMapper.addUser(user);
        int i = 1 / 0;
    }
}
